package com.lin.missyou.util;

import com.lin.missyou.bo.PageCounter;
import org.omg.CORBA.PUBLIC_MEMBER;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;

public class CommonUtil {
    public static PageCounter convertToPageParameter(Integer start, Integer count) {
        int page = start / count;
        PageCounter pageCounter = PageCounter.builder()
                .page(page)
                .count(count)
                .build();
        return pageCounter;
    }

    public static Calendar addSomeSeconds(Calendar calendar, int seconds) {
        calendar.add(Calendar.SECOND, seconds);
        return calendar;
    }

    public static Boolean isDateValid(Date now, Date start, Date end) {
        long nowTime = now.getTime();
        if (nowTime < start.getTime() || nowTime > end.getTime()) {
            return false;
        }
        return true;
    }

    public static boolean isOutOfDate(Date expiredTime) {
        long now = Calendar.getInstance().getTimeInMillis();
        if (now > expiredTime.getTime()) {
            return true;
        }
        return false;
    }

    /**
     * 单价：元转换为分
     *
     * @param p
     * @return
     */
    public static String yuanToFenPlainString(BigDecimal p) {
        p = p.multiply(new BigDecimal("100"));
        return CommonUtil.toPlain(p);

    }

    /**
     * 把BigDecimal转换为字符串
     *
     * @param p
     * @return
     */
    public static String toPlain(BigDecimal p) {
        return p.stripTrailingZeros().toPlainString();
    }

    public static String timeStamp10() {
        Long timestamp13 = Calendar.getInstance().getTimeInMillis();
        String timestamp13Str = timestamp13.toString();
        return timestamp13Str.substring(0, timestamp13Str.length() - 3);

    }
}
